{% extends "base.html" %}
{% if board.bo_use_sideview %}
    {% import "/sideview/macros.html" as sideview %}
{% endif %}

{% block title %}{{ board.subject }} {{ current_page }} 页数{% endblock title %}
{% block subtitle %}{{ board.subject }}{% endblock subtitle %}

{% block head %}
    <link rel="stylesheet" href="{{ theme_asset(request, 'css/board_common.css?ver=1.0.0') }}">
    <link rel="stylesheet" href="{{ theme_asset(request, 'css/board_skin_basic.css?ver=1.0.0') }}">
{% endblock head %}

{% block content %}
{% set is_admin=get_admin_type(request, request.state.login_member.mb_id, board=board) %}
{% set sca=request.query_params.sca %}
{% set sod_reverse="asc" if request.query_params.sod == "desc" else "desc" %}

<div id="bo_basic_list" class="bo_common bo_list" style="width:{{ table_width }}">

    {% if board.bo_use_category %}
    <div class="list_category">
        <h2 class="blind">{{ board.subject }} 类别</h2>
        <ul>
            <li>
                <a href="{{ request.url.replace_query_params() }}" {% if not sca %}class="active"{% endif %}>已满</a>
            </li>
            {% for category in categories %}
            <li>
                <a href="{{ request.url.replace_query_params(sca=category) }}" {% if sca == category %}class="active"{% endif %}>{{ category }}</a>
            </li>
            {% endfor %}
        </ul>
    </div>
    {% endif %}

    <form name="fboardlist" id="fboardlist" action="" onsubmit="return fboardlist_submit(this);" method="post">

        <input type="hidden" name="bo_table" value="{{ board.bo_table }}">
        <input type="hidden" name="sw" value="">
        <input type="hidden" name="sfl" value="{{ request.query_params.sfl }}">
        <input type="hidden" name="stx" value="{{ request.query_params.stx }}">
        <input type="hidden" name="spt" value="{{ request.query_params.spt }}">
        <input type="hidden" name="sca" value="{{ request.query_params.sca }}">
        <input type="hidden" name="sst" value="{{ request.query_params.sst }}">
        <input type="hidden" name="sod" value="{{ request.query_params.sod }}">
        <input type="hidden" name="page" value="{{ current_page }}">
        <input type="hidden" name="token" value="">
        <input type="hidden" name="act_button" value="">

        <div class="list_header">

            <div class="total">
                <span>Total {{ total_count|number_format }}枪</span>
                {{ current_page|number_format }} 页数
            </div>

            <ul>
                <li>
                    <button type="button" class="search_opener btn_b01 btn" title="公告板搜索">
                        <i class="fa fa-search" aria-hidden="true"></i>
                        <span class="blind">公告板搜索</span>
                    </button>
                </li>
                {% if is_write %}
                <li>
                    <a href="{{ url_for('write_form_add', bo_table=board.bo_table)|set_query_params(request) }}" class="btn_b01 btn" title="写作">
                        <i class="fa fa-pencil" aria-hidden="true"></i>
                        <span class="blind">写作</span>
                    </a>
                </li>
                {% endif %}
                {% if is_admin %}
                <li class="buttons_more">
                    <button type="button" class="more_opener btn_b01 btn" title="公告板列表选项">
                        <i class="fa fa-ellipsis-v" aria-hidden="true"></i>
                        <span class="blind">公告板列表选项</span>
                    </button>
                    <ul class="more">
                        <li>
                            <button type="submit" name="btn_submit" value="删除所选内容" onclick="document.pressed=this.value"><i class="fa fa-regular fa-trash-can" aria-hidden="true"></i> 删除所选内容</button>
                        </li>
                        <li>
                            <button type="submit" name="btn_submit" value="选择复制" onclick="document.pressed=this.value"><i class="fa fa-regular fa-file" aria-hidden="true"></i> 选择复制</button>
                        </li>
                        <li>
                            <button type="submit" name="btn_submit" value="选择移动" onclick="document.pressed=this.value"><i class="fa fa-arrows" aria-hidden="true"></i> 选择移动</button>
                        </li>
                    </ul>
                </li>
                <li>
                    <a href="{{ url_for('board_form', bo_table=board.bo_table) }}" class="btn_admin btn" title="经理">
                        <i class="fa fa-cog fa-spin fa-fw"></i>
                        <span class="blind">经理</span>
                    </a>
                </li>
                {% endif %}
            </ul>

        </div>

        <table class="list_table">
            <caption class="blind">免费公告列表</caption>
            <thead>
                <tr>
                    {% if is_admin %}
                    <th scope="col" class="chk_box">
                        <input type="checkbox" id="chkall" onclick="if (this.checked) all_checked(true); else all_checked(false);">
                        <label for="chkall">
                            <span>&nbsp;</span>
                            <b class="blind">当前页面帖子的完整选择</b>
                        </label>
                    </th>
                    {% endif %}
                    <th scope="col">编号</th>
                    {% if board.bo_use_category %}
                    <th scope="col">分类</th>
                    {% endif %}
                    <th scope="col">标题</th>
                    <th scope="col">作家</th>
                    <th scope="col"><a href="{{ request.url.include_query_params(sst="wr_hit", sod=sod_reverse) }}">询价</a></th>
                    {% if board.bo_use_good %}
                    <th scope="col"><a href="{{ request.url.include_query_params(sst="wr_good", sod=sod_reverse) }}">待定</a></th>
                    {% endif %}
                    {% if board.bo_use_nogood %}
                    <th scope="col"><a href="{{ request.url.include_query_params(sst="wr_nogood", sod=sod_reverse) }}">非推荐</a></th>
                    {% endif %}
                    <th scope="col"><a href="{{ request.url.include_query_params(sst="wr_datetime", sod=sod_reverse) }}">日期</a></th>
                </tr>
            </thead>
            <tbody>
                {% for write in notice_writes %}
                <tr class="is_notice">
                    {% if is_admin %}
                    <td class="table_check chk_box"></td>
                    {% endif %}
                    <td class="table_wrid">公共</td>
                    {% if board.bo_use_category and write.ca_name %}
                    <td class="table_category">
                        <a href="{{ request.url.replace_query_params(sca=write.ca_name) }}" class="category_link">
                            {{ write.ca_name }}
                        </a>
                    </td>
                    {% endif %}
                    <td class="table_subject">
                        {% if "secret" in write.wr_option %}
                            <i class="fa fa-lock" aria-hidden="true"></i>
                        {% endif %}
                        <a href="{{ url_for('read_post', bo_table=board.bo_table, wr_id=write.wr_id)|set_query_params(request) }}">
                            {{ write.subject }}
                        </a>
                        {% if write.wr_comment %}
                        <span class="blind">评论</span>
                        <span class="count_comment">{{ write.wr_comment }}</span>
                        <span class="blind">狗</span>
                        {% endif %}
                        {% if write.icon_new %}
                        <span class="new_icon">N</span>
                        <span class="blind">新写作</span>
                        {% endif %}
                        {% if write.icon_hot %}
                        <i class="fa fa-heart" aria-hidden="true"></i>
                        <span class="blind">新写作</span>
                        {% endif %}
                        {% if write.icon_file %}
                        <i class="fa fa-download" aria-hidden="true"></i>
                        <span class="blind">有一个附件</span>
                        {% endif %}
                        {% if write.icon_link %}
                        <i class="fa fa-link" aria-hidden="true"></i>
                        <span class="blind">有一个链接</span>
                        {% endif %}
                    </td>
                    <td class="table_writer">
                        {% if board.bo_use_sideview %}
                            {{ sideview.get(request, write.mb_id, write.name, write.wr_email, write.wr_homepage)|safe }}
                        {% else %}
                            <span class="sv_member">{{ write.name }}</span>
                        {% endif %}
                    </td>
                    <td class="table_hit" data-label="点击数">{{ write.wr_hit|number_format }}</td>
                    {% if board.bo_use_good %}
                    <td class="table_good" data-label="待定">{{ write.wr_good|number_format }}</td>
                    {% endif %}
                    {% if board.bo_use_nogood %}
                    <td class="table_nogood" data-label="灯光">{{ write.wr_nogood|number_format }}</td>
                    {% endif %}
                    <td class="table_datetime">{{ write.datetime }}</td>
                </tr>
                {% endfor %}

                {% for write in writes %}
                {% set reply_depth=write.wr_reply|length %}
                <tr class="{{ loop.cycle("", "even") }}">
                    {% if is_admin %}
                    <td class="table_check chk_box">
                        {% if not write.is_notice %}
                        <input type="checkbox" name="chk_wr_id[]" value="{{ write.wr_id }}" id="chk_wr_id_{{ loop.index }}">
                        <label for="chk_wr_id_{{ loop.index }}">
                            <span>&nbsp;</span>
                            <b class="blind">{{ write.subject }}</b>
                        </label>
                        {% endif %}
                    </td>
                    {% endif %}
                    <td class="table_wrid">
                        {% if wr_id == write.wr_id %}
                            <span class="current_article">在开幕期间</span>
                        {% else %}
                            {{ write.num }}
                        {% endif %}
                    </td>
                    {% if board.bo_use_category %}
                    <td class="table_category">
                        {% if write.ca_name %}
                        <a href="{{ request.url.replace_query_params(sca=write.ca_name) }}" class="category_link">
                            {{ write.ca_name }}
                        </a>
                        {% endif %}
                    </td>
                    {% endif %}
                    <td class="table_subject" style="padding-left:{{ reply_depth * 10 }}px">
                        {% if write.wr_reply %}
                            <i class="fa fa-reply"></i>
                            <span class="blind">答案</span>
                        {% endif %}
                        {% if "secret" in write.wr_option %}
                            <i class="fa fa-lock" aria-hidden="true"></i>
                        {% endif %}
                        <a href="{{ url_for('read_post', bo_table=board.bo_table, wr_id=write.wr_id)|set_query_params(request) }}">
                            {{ write.wr_subject }}
                        </a>
                        {% if write.wr_comment %}
                        <span class="blind">评论</span>
                        <span class="count_comment">{{ write.wr_comment }}</span>
                        <span class="blind">狗</span>
                        {% endif %}
                        {% if write.icon_new %}
                        <span class="new_icon">N</span>
                        <span class="blind">新写作</span>
                        {% endif %}
                        {% if write.icon_hot %}
                        <i class="fa fa-heart" aria-hidden="true"></i>
                        <span class="blind">流行写作</span>
                        {% endif %}
                        {% if write.icon_file %}
                        <i class="fa fa-download" aria-hidden="true"></i>
                        <span class="blind">有一个附件</span>
                        {% endif %}
                        {% if write.icon_link %}
                        <i class="fa fa-link" aria-hidden="true"></i>
                        <span class="blind">有一个链接</span>
                        {% endif %}
                    </td>
                    <td class="table_writer">
                        {% if board.bo_use_sideview %}
                            {{ sideview.get(request, write.mb_id, write.name, write.wr_email, write.wr_homepage)|safe }}
                        {% else %}
                            <span class="{% if write.mb_id %}sv_member{% else %}sv_guest{% endif %}">
                                {{ write.name }}
                            </span>
                        {% endif %}
                    </td>
                    <td class="table_hit" data-label="点击数">{{ write.wr_hit|number_format }}</td>
                    {% if board.bo_use_good %}
                    <td class="table_good" data-label="待定">{{ write.wr_good|number_format }}</td>
                    {% endif %}
                    {% if board.bo_use_nogood %}
                    <td class="table_nogood" data-label="灯光">{{ write.wr_nogood|number_format }}</td>
                    <td class="table_nogood" data-label="비추">{{ write.wr_nogood|number_format }}</td>
                    {% endif %}
                    <td class="table_datetime">{{ write.wr_datetime|datetime_format('%y-%m-%d') }}</td>
                </tr>
                {% else %}
                <tr><td colspan="9" class="empty_table">无帖子.</td></tr>
                {% endfor %}
            </tbody>
        </table>

        {{ paging|safe }}

        <div class="list_footer">
            <div>
                {% if prev_spt %}
                <a href="{{ request.url.include_query_params(spt=prev_spt) }}" class="btn02">上一个搜索</a>
                {% endif %}
                {% if next_spt %}
                <a href="{{ request.url.include_query_params(spt=next_spt) }}" class="btn02">下一次搜索</a>
                {% endif %}
            </div>

            <ul>
                {% if is_admin %}
                <li>
                    <a href="{{ url_for('board_form', bo_table=board.bo_table) }}" class="btn_admin btn" title="经理">
                        <i class="fa fa-cog fa-spin fa-fw"></i><span class="blind">经理</span>
                    </a>
                </li>
                {% endif %}
                {% if board.bo_use_rss_view %}
                <li>
                    <a href="" class="btn_b01 btn" title="RSS">
                        <i class="fa fa-rss" aria-hidden="true"></i><span class="blind">RSS</span>
                    </a>
                </li>
                {% endif %}
                {% if is_write %}
                <li>
                    <a href="{{ url_for('write_form_add', bo_table=board.bo_table)|set_query_params(request) }}" class="btn_b01 btn" title="写作">
                        <i class="fa fa-pencil" aria-hidden="true"></i>
                        <span class="blind">写作</span>
                    </a>
                </li>
                {% endif %}
            </ul>
        </div>

    </form>

    <div class="list_search">

        <form name="fsearch" method="get" class="search_modal">
            <input type="hidden" name="sca" value="{{ request.query_params.sca }}">
            <input type="hidden" name="sop" value="{{ request.query_params.sop }}">

            <div class="modal_title">搜索</div>

            <label for="sfl" class="blind">搜索目标</label>
            <select name="sfl" id="sfl">
                <option value="wr_subject" {{ get_selected(request.query_params.sfl, "wr_subject")|safe }}>标题</option>
                <option value="wr_content" {{ get_selected(request.query_params.sfl, "wr_content")|safe }}>内容</option>
                <option value="wr_subject||wr_content" {{ get_selected(request.query_params.sfl, "wr_subject||wr_content")|safe }}>标题+内容</option>
                <option value="wr_name,1" {{ get_selected(request.query_params.sfl, "wr_name,1")|safe }}>作家</option>
                <option value="wr_name,0" {{ get_selected(request.query_params.sfl, "wr_name,0")|safe }}>作家(机头)</option>
            </select>

            <div class="modal_keyword">
                <label for="stx" class="blind">搜索词<strong> 必不可少的</strong></label>
                <input type="text" name="stx" value="{{ request.query_params.stx }}" required id="stx" size="25" maxlength="20" placeholder=" 请输入您的搜索词">

                <button type="submit" value="搜索">
                    <i class="fa fa-search" aria-hidden="true"></i>
                    <span class="blind">搜索</span>
                </button>
            </div>

            <button type="button" class="modal_close">
                <i class="fa fa-xmark" aria-hidden="true"></i>
                <span class="blind">关闭</span>
            </button>
        </form>

        <div class="search_mask"></div>

    </div>

    <script>
        jQuery(function($){
            $(".search_opener").on("click", function() {
                $(".list_search").toggle();
            })
            $('.search_modal .modal_close, .list_search .search_mask').click(function(){
                $('.list_search').hide();
            });
        });
    </script>

</div>

{% if is_admin %}
<noscript>
    <p>如果不使用yvp脚本<br>请小心删除选择没有任何验证过程。.</p>
</noscript>
<script>
function all_checked(sw) {
    var f = document.fboardlist;

    for (var i = 0; i < f.length; i++) {
        if (f.elements[i].name == "chk_wr_id[]")
            f.elements[i].checked = sw;
    }
}

function fboardlist_submit(f) {
    var chk_count = 0;

    for (var i = 0; i < f.length; i++) {
        if (f.elements[i].name == "chk_wr_id[]" && f.elements[i].checked)
            chk_count++;
    }

    if (!chk_count) {
        alert(document.pressed + "选择您想要的一个或多个帖子.");
        return false;
    }

    if(document.pressed == "选择复制") {
        select_copy("copy");
        return;
    }

    if(document.pressed == "选择移动") {
        select_copy("move");
        return;
    }

    if(document.pressed == "删除所选内容") {
        if (!confirm("是否确实要删除所选帖子?\n\n您无法恢复一次删除的材料\n\n如果你选择一个有回复的帖子\n您还必须选择答案帖子。."))
            return false;

        f.removeAttribute("target");
        f.action = "{{ url_for('list_delete', bo_table=board.bo_table)|set_query_params(request)|safe }}";
    }

    f.token.value = generate_token();

    return true;
}

function select_copy(sw) {
    var f = document.fboardlist;
    var sub_win = window.open("", "move", "left=50, top=50, width=500, height=550, scrollbars=1");

    f.sw.value = sw;
    f.target = "move";
    f.action = "{{ url_for('move_post', bo_table=board.bo_table)|safe }}";
    f.submit();
}

jQuery(function($){
    $(".buttons_more .more_opener").on("click", function(e) {
        e.stopPropagation();
        $(this).next(".more").toggle();
    })
    $(document).on("click", function (e) {
        if(!$(e.target).closest(".more_opener").length) {
            $(".buttons_more .more").hide();
        }
    });
});
</script>
{% endif %}
{% endblock content %}